from django.contrib import admin
from .models import City, DataCenter, Host, HostPassword, HostPingLog


@admin.register(City)
class CityAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'created_at', 'updated_at']
    search_fields = ['name', 'code']
    list_filter = ['created_at']


@admin.register(DataCenter)
class DataCenterAdmin(admin.ModelAdmin):
    list_display = ['name', 'city', 'address', 'created_at']
    list_filter = ['city', 'created_at']
    search_fields = ['name', 'address']


@admin.register(Host)
class HostAdmin(admin.ModelAdmin):
    list_display = ['hostname', 'ip_address', 'status', 'os_type', 'data_center', 'last_ping_status', 'last_ping_time']
    list_filter = ['status', 'os_type', 'data_center__city', 'data_center', 'last_ping_status']
    search_fields = ['hostname', 'ip_address', 'description']
    readonly_fields = ['last_ping_time', 'last_ping_status']


@admin.register(HostPassword)
class HostPasswordAdmin(admin.ModelAdmin):
    list_display = ['host', 'password_changed_at', 'next_change_time']
    list_filter = ['password_changed_at']
    readonly_fields = ['encrypted_password', 'password_changed_at', 'next_change_time']


@admin.register(HostPingLog)
class HostPingLogAdmin(admin.ModelAdmin):
    list_display = ['host', 'ping_time', 'is_reachable', 'response_time']
    list_filter = ['is_reachable', 'ping_time', 'host__data_center__city']
    search_fields = ['host__hostname', 'host__ip_address']
    readonly_fields = ['ping_time']
